﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace CruxCRUDBuilderHelper.Utility
{
    public class UtilityMethod
    {
        public string GetIteratorPattern(string content)
        {
            int pos, next;
            if ((pos = content.IndexOf("~[")) > -1)
                next = content.IndexOf("]~", pos + 2);
            else
                return String.Empty;
            return content.Substring(pos + 2, next - (pos + 2));
        }

        internal string GetIteratorPattern2(string content)
        {

            int pos, next;

            if ((pos = content.IndexOf("~[[")) > -1)
            {
                next = content.IndexOf("]]~", pos + 3);

            }
            else
                return String.Empty;

            return content.Substring(pos + 3, next - (pos + 3));
        }

        internal string GetIteratorPatternForDependentField(string content)
        {
            int pos, next;
            if ((pos = content.IndexOf("$[")) > -1)
                next = content.IndexOf("]$", pos + 2);
            else
                return String.Empty;
            return content.Substring(pos + 2, next - (pos + 2));
        }

        internal string GetHeader(string field)
        {
            StringBuilder word = new StringBuilder(string.Empty);
            foreach (Char c in field)
            {
                if (Char.IsUpper(c))
                    word.Append(' ');
                word.Append(c);
            }
            return (word.ToString());
        }
    }
}
